<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>webSorket测试</title>
  </head>
  <body></body>
  <script>
    window.onload = function () {
      initWs();
    };

    var ws;
    function initWs() {
      if (window.WebSocket) {
        ws = new WebSocket("ws://localhost:8080/gobank");

        ws.onopen = function () {
          console.log("链接成功");
        };
        ws.onclose = function () {
          console.log("链接关闭");
        };
        ws.onerror = function (e) {
          console.log("链接失败");
        };
        ws.onmessage = function (resp) {
          console.log("有一个消息：" + resp.data);
        };
      } else {
        alert("不支持websocket");
      }
    }
  </script>
</html>
